package com.example.dryyzx.dao;

import com.example.dryyzx.entity.BedRecord;
import org.apache.ibatis.jdbc.SQL;

public class BedRecordSqlProvider {
    public String insertSelective(BedRecord record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("bed_record");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getBedId() != null) {
            sql.VALUES("bed_id", "#{bedId,jdbcType=INTEGER}");
        }
        
        if (record.getCustomerId() != null) {
            sql.VALUES("customer_id", "#{customerId,jdbcType=INTEGER}");
        }
        
        if (record.getOccupiedTime() != null) {
            sql.VALUES("occupied_time", "#{occupiedTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getLeavingTime() != null) {
            sql.VALUES("leaving_time", "#{leavingTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getEnable() != null) {
            sql.VALUES("enable", "#{enable,jdbcType=BIT}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(BedRecord record) {
        SQL sql = new SQL();
        sql.UPDATE("bed_record");
        
        if (record.getBedId() != null) {
            sql.SET("bed_id = #{bedId,jdbcType=INTEGER}");
        }
        
        if (record.getCustomerId() != null) {
            sql.SET("customer_id = #{customerId,jdbcType=INTEGER}");
        }
        
        if (record.getOccupiedTime() != null) {
            sql.SET("occupied_time = #{occupiedTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getLeavingTime() != null) {
            sql.SET("leaving_time = #{leavingTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getEnable() != null) {
            sql.SET("enable = #{enable,jdbcType=BIT}");
        }
        
        sql.WHERE("id = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
}